import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';

enum Api {
  page = '/food-service/store/pageStore',
  list = '/food-service/store/listStore',
  save = '/food-service/store/saveStore',
  get = '/food-service/store/getStore',
  edit ='/food-service/store/updateStore',
  setting ='/food-service/store/setting',
  deleteStore = '/food-service/store/deleteStore',
  deleteBatch = '/food-service/store/batchDeleteStore',
}

/**
 * 列表接口
 * @param params
 */
export const pageStore = (params) => defHttp.get({url: Api.page, params});
export const listStore = (params) => defHttp.get({url: Api.list, params});


/**
 * 删除
 */
export const deleteStore = (params,handleSuccess) => {
  return defHttp.delete({url: Api.deleteStore, params}, {joinParamsToUrl: true}).then(() => {
    handleSuccess();
  });
}

/**
 * 批量删除
 * @param params
 */
export const batchDeleteStore = (params, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除选中数据',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.deleteBatch, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}


/**
 * 保存或者更新
 * @param params
 */
export const saveOrUpdateStore = (params, isUpdate) => {
  return defHttp.post({url: isUpdate ? Api.edit : Api.save, params});
}


export const settingStore = (params) => {
  return defHttp.post({url: Api.setting, params});
}